package cn.silver.module.system.domain;


import cn.silver.framework.mybatis.annotation.Table;
import cn.silver.framework.mybatis.annotation.TableField;
import cn.silver.framework.mybatis.domain.BaseEntity;
import cn.silver.framework.mybatis.enums.SearchTypeEnums;
import cn.silver.framework.satoken.model.LoginUser;
import cn.silver.framework.satoken.utils.LoginHelper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serial;

/**
 * 用户邮箱配置对象 sys_user_mail
 *
 * @author hb
 * @date 2022-07-06
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "sys_user_mail")
@EqualsAndHashCode(callSuper = true)
@Schema(name = "SysUserMail", description = "SysUserMail对象")
public class SysUserMail extends BaseEntity {
    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 用户信息
     */
    @TableField(name = "user_id", searchType = SearchTypeEnums.EQ)
    @Schema(title = "用户信息")
    private String userId;

    /**
     * 邮箱地址
     */
    @TableField(name = "mail_addr", searchType = SearchTypeEnums.EQ)
    @Schema(title = "邮箱地址")
    private String mailAddr;

    /**
     * smtp服务器地址
     */
    @TableField(name = "smtp_addr", searchType = SearchTypeEnums.EQ)
    @Schema(title = "smtp服务器地址")
    private String smtpAddr;

    /**
     * smtp登录用户名
     */
    @TableField(name = "smtp_user", searchType = SearchTypeEnums.EQ)
    @Schema(title = "smtp登录用户名")
    private String smtpUser;

    /**
     * smtp登录密码
     */
    @TableField(name = "smtp_pass", searchType = SearchTypeEnums.EQ)
    @Schema(title = "smtp登录密码")
    private String smtpPass;

    @Override
    public void preInsert() {
        super.preInsert();
        LoginUser user = LoginHelper.getLoginUser();
        if (user != null) {
            this.userId = user.getId();
        }
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("userId", getUserId())
                .append("mailAddr", getMailAddr())
                .append("smtpAddr", getSmtpAddr())
                .append("smtpUser", getSmtpUser())
                .append("smtpPass", getSmtpPass())
                .toString();
    }
}
